package com.stylefeng.guns.core.base.tips;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.constant.AppCodeEnum;
import com.stylefeng.guns.core.page.PageInfoBT;

import java.io.PrintWriter;
import java.util.List;
/**
 * Created by Admin on 2017/10/2.
 */
public class ResultTip<T> extends Tip {
    private T data;//返回单个结果使用
    private List<T> list;//返回数组使用
    private PageInfoBT<T> page;//分页返回

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public PageInfoBT<T> getPage() {
        return page;
    }

    public void setPage(PageInfoBT<T> page) {
        this.page = page;
    }

    public ResultTip(T data) {
        this();
        this.data = data;
    }
    public ResultTip(List<T> list) {
        this();
        this.list = list;
    }
    public ResultTip(PageInfoBT<T> page) {
        this();
        this.page = page;
    }
    public ResultTip(){
        this.message= AppCodeEnum.SUCCESS.getMessage();
        this.code=AppCodeEnum.SUCCESS.getCode();
    }
    public ResultTip(AppCodeEnum em,PrintWriter writer){
        this.message= em.getMessage();
        this.code=em.getCode();
        Object json = JSON.toJSON(this);
        writer.print(json);
        writer.close();
    }
}
